﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLiSinhVien_v01.DAO;
using QuanLiSinhVien_v01.DTO;
namespace QuanLiSinhVien_v01.BUS.Pattern
{
    class InfoOfSubjectStragety : InfoStrategy
    {
        public override Object[] Explore()
        {
            Object[] result;
            MonHocDao monhocDAO = new MonHocDao();
            result = monhocDAO.GetList();
            return result;
        }
        public override Object[] Search(string keyword)
        {
            Object[] result;
            MonHocDao monhocDAO = new MonHocDao();
            result = monhocDAO.Search(keyword);
            return result;
        }
        public override void Update(Object obj)
        {
           MonHocDto monhoc = new MonHocDto();
            DataGridViewRow row = (DataGridViewRow)obj;
            monhoc.MaMonHoc = row.Cells[0].Value.ToString();
            monhoc.TenMonHoc = row.Cells[1].Value != null ? row.Cells[1].Value.ToString() : "";
            monhoc.CreditNumber = row.Cells[2].Value != null ? Int32.Parse( row.Cells[2].Value.ToString()) : 1;
            monhoc.MaHocKy = row.Cells[3].Value != null ? row.Cells[3].Value.ToString() : "";
            monhoc.GhiChu = row.Cells[4].Value != null ? row.Cells[4].Value.ToString() : "";
            MonHocDao sinhvienDAO = new MonHocDao();
            sinhvienDAO.MonHoc = monhoc;
            sinhvienDAO.Update();
        }
        public override void Delete(Object obj)
        {
            MonHocDto monhoc = new MonHocDto();
            DataGridViewRow row = (DataGridViewRow)obj;
            monhoc.MaMonHoc = row.Cells[0].Value.ToString();
            monhoc.TenMonHoc = row.Cells[1].Value != null ? row.Cells[1].Value.ToString() : "";
            monhoc.CreditNumber = row.Cells[2].Value != null ? Int32.Parse(row.Cells[2].Value.ToString()) : 1;
            monhoc.MaHocKy = row.Cells[3].Value != null ? row.Cells[3].Value.ToString() : "";
            monhoc.GhiChu = row.Cells[4].Value != null ? row.Cells[4].Value.ToString() : "";
            MonHocDao monhocDAO = new MonHocDao();
            monhocDAO.MonHoc = monhoc;
            monhocDAO.Delete();
        }

        public override void Insert(Object obj)
        {
            MonHocDto monhoc = new MonHocDto();
            monhoc = (MonHocDto)obj;
            MonHocDao monhocDAO = new MonHocDao();
            monhocDAO.MonHoc = monhoc;
            monhocDAO.Insert();
        }
    }
}
